package cn.itcast.jdbc;

import cn.itcast.util.JDBCUtil;

import java.sql.*;
import java.util.Scanner;

/*
事务
 */
public class JDBC_Demo9 {

    public static void login() throws SQLException {
        Connection conn = null;
        Statement statement = null;
        JDBCUtil jdbcUtil = new JDBCUtil();
        String sql1 = "update account set banlance = banlance-5000 where id = 1";
        String sql2 = "update account set banlance = banlance+5000 where id = 2";
        conn = JDBCUtil.getConnection();
        try {
            conn.setAutoCommit(false);
            Statement stmt = conn.createStatement();
            stmt.executeUpdate(sql1);
//            int a = 5 / 0;
            stmt.executeUpdate(sql2);
            conn.commit();
        }catch (Exception e)
        {
            conn.rollback();
        }



    }

    public static void main(String[] args) throws SQLException {
        login();
    }
}
